package com.hybao.topApi;

import java.util.List;

import com.hybao.common.TopBaseClient;
import com.taobao.api.ApiException;
import com.taobao.api.domain.User;
import com.taobao.api.request.UserGetRequest;
import com.taobao.api.request.UsersGetRequest;
import com.taobao.api.response.UserGetResponse;
import com.taobao.api.response.UsersGetResponse;

public class UserTopService extends TopBaseClient{
	
	public User getUserFromTopWithNick(String userNick,String sessionKey){
		UserGetRequest req=new UserGetRequest();
		req.setFields("user_id,nick,seller_credit,location,birthday,email");
		req.setNick(userNick);
		UserGetResponse response = null;
		try {
			if(sessionKey != null){
				response = this.getClient().execute(req,sessionKey);
			}
			else{
				response = this.getClient().execute(req);
			}
		} catch (ApiException e) {
			this.getLog().error("get User from top failed: " + userNick, e);
		}
		if(response != null && response.isSuccess()){
			return response.getUser();
		}
		else{
			return null;
		}
	}
	
	public List<User> getUserListFromTopWithNicks(String nicks){
		UsersGetRequest req=new UsersGetRequest();
		req.setFields("user_id,nick,seller_credit,location,birthday,email");
		req.setNicks(nicks);
		UsersGetResponse response = null;
		try {
			response =  this.getClient().execute(req);
		} catch (ApiException e) {
			this.getLog().error("get User from top failed: " + nicks, e);
		}
		if(response != null && response.isSuccess()){
			return response.getUsers();
		}
		else{
			return null;
		}
	}
}
